﻿@using SH = EMoney.IStock.Client.Framework.StringHelper;

@using EMoney.IStock.Client.Models.MC;
@{
    Layout = null;

    string userName = string.Empty;
    string userNameShow = string.Empty;
    string mobile = string.Empty;
    string email = string.Empty;
    int iNum = 0;
    int curLevel = 0;
    int nextLevelNeedINum = 0;
    int continueLoginDays = 0;
    int nextContinueLoginINum = 0;
    string curUserpic = string.Empty;
    string curUserPicUrl = string.Empty;
    string strUserRightsCount = string.Empty;
    string continueLoginTxt = string.Empty;
    string completedTaskID = string.Empty;
    
    if(ViewBag.MyInfo != null)
    {
        MC_MyInfo myInfo = ViewBag.MyInfo;
        
        userName = myInfo.UserName;
        userNameShow = userName;

        if (string.IsNullOrEmpty(userNameShow))
        {
            userNameShow = "设置昵称"; 
        }
        
        mobile = myInfo.Mobile;
        email = myInfo.Email;
        iNum = myInfo.iNum;
        curLevel = myInfo.Level;
        nextLevelNeedINum = myInfo.NextLeveliNum - iNum;
        continueLoginDays = myInfo.ContinueLoginDays;

        if (!string.IsNullOrEmpty(myInfo.UserPic))
        {
            curUserpic = myInfo.UserPic;
        }
        else
        {
            curUserpic = "0"; 
        }

        nextContinueLoginINum = SH.GetContinueLoginINum(continueLoginDays + 1);
        if (nextContinueLoginINum == 0)
        {
            nextContinueLoginINum = 5; 
        }

        if (string.IsNullOrEmpty(myInfo.ContinueLoginTips))
        {
            continueLoginTxt = string.Concat(continueLoginDays, "|", nextContinueLoginINum, "|25");
        }

        //已完成任务编号
        System.Text.StringBuilder completedIDs = new System.Text.StringBuilder();
        
        Dictionary<int,DateTime> dicCompleted = myInfo.CompletedSingleTaskID;
        if (dicCompleted != null && dicCompleted.Count > 0)
        {
            foreach (KeyValuePair<int, DateTime> kvp in dicCompleted)
            {
                completedIDs.Append(kvp.Key).Append(",");
            }
        }
        
        dicCompleted = myInfo.CompletedDailyTaskID;
        if (dicCompleted != null && dicCompleted.Count > 0)
        {
            foreach (KeyValuePair<int, DateTime> kvp in dicCompleted)
            {
                completedIDs.Append(kvp.Key).Append(",");
            }
        }

        completedTaskID = completedIDs.ToString();
    }

    string associatedLogin = string.Empty;
    if (!string.IsNullOrEmpty(Request["associatedlogin"]))
    {
        associatedLogin = Request["associatedlogin"]; //1是联合登录 0则不是
    }
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>爱炒股会员中心</title>
    <link rel="stylesheet" type="text/css" href="@SH.GetStaticFile("IStockClientStatic/mc/css/main.css")" id="linkcss" />
    <script src="http://static.emoney.cn/js/libs/jquery.min.1.8.3.js" type="text/javascript"></script>
    <!--[if lt IE 7]>
    <script>document.execCommand("BackgroundImageCache",false,true);</script>
    <![endif]-->
    <style type="text/css">
        .jscroll-c{top: 0px; z-index: 9999; zoom: 1; position: relative;overflow:hidden;}
        .jscroll-e{height: 100%; top: 0px; right: 0; -moz-user-select: none; position: absolute; overflow: hidden; z-index: 10000; /*background: url(http://static.emoney.cn/www/emfastock/img/scrollbar.gif) -33px 0 repeat-y;*/}
        .jscroll-u{position: absolute; top: 0px; width: 100%; left: 0; overflow: hidden; background:trasparent;}
        .jscroll-h{position: absolute;left: 0px; -moz-user-select: none; border: 0; overflow: hidden; text-align: center;}
        .jscroll-bart{width: 11px; height: 6px; background: url(http://static.emoney.cn/www/emfastock/img/scrollbar.gif?) no-repeat -1px -1px; overflow: hidden;}
        .jscroll-h-i{width: 13px; height: 5px; background: url(http://static.emoney.cn/www/emfastock/img/scrollbar.gif?) repeat-y -16px top; overflow: hidden;}
        .jscroll-h-s{width: 13px; height: 100%; background: url(http://static.emoney.cn/www/emfastock/img/scrollbar.gif?) no-repeat -52px center; overflow: hidden;}
        .jscroll-barb{width: 11px; height: 6px; background: url(http://static.emoney.cn/www/emfastock/img/scrollbar.gif?) no-repeat -1px -10px; overflow: hidden;}
        .jscroll-d{position: absolute; bottom: 0px; width: 100%; left: 0; overflow: hidden; background:trasparent;}
        .scroll-pane{ margin-left:5px;}
    </style>
</head>
<body>
    <div class="pop_tx">
      <div class="close"><a href="javascript:;" hidefocus="true"><img src="@SH.GetStaticFile("IStockClientStatic/mc/images/close.jpg")" width="30" height="30"  alt=""/></a></div>
      <div class="p1">更换头像</div>
      <div class="txk">
        <div id="scrollBoxPic" class="scrollBox" scrollflag style="height:250px;">
        <ul id="ulUserPic">
            @{
                if (ViewBag.UserPicList != null && ViewBag.UserPicList.Count > 0)
                {
                    string liclass = string.Empty;
                    foreach (UserPic userPic in ViewBag.UserPicList)
                    { 
                        if(curUserpic.Equals(userPic.Name))
                        {
                            curUserPicUrl = userPic.Url;
                            liclass = "on";
                        }
                        else
                        {
                            liclass = string.Empty;
                        }
                        
                        <li class="@liclass" name="@userPic.Name" url="@userPic.Url"><div class="on"></div><img src="@userPic.Url" style="width:77px;height:77px;" alt=""/></li>
                    }
                }
                }
          <div class="clear"></div>
        </ul>
        </div>
      </div>
    </div>
    <div class="main">
        <div class="cover" title="点击更换头像" style="cursor:pointer;"></div>
        <div class="user_pic">
            <img src="@curUserPicUrl" style="width:100px;height:100px;" alt="" /></div>
        <div class="main_infk">
            <div class="user_infk">
                <ul>
                    <li><span id="spanUserNameTips" style="color:#E7401C;display:none;"></span><span id="spanUserName" title="点击设置昵称" style="cursor:pointer;font-weight:bold;">@SH.StringSubstrLen(userNameShow, 22)</span><input id="txtUserName" maxlength="15" type="text" value="@userName" style="width:170px;display:none;" /></li>
                    <li><span class="coin" id="spanINum" title="我是i豆，是您社区地位的象征、升级成长的利器，有趣、有用、有惊喜的i豆使用攻略即将推出，敬请期待吧！">@iNum</span>@*<a href="javascript:;">去兑换&gt;&gt;</a>*@</li>
                    <li>手机号码：<span id="spanBindMobile">
                        @{
                            if (string.IsNullOrEmpty(mobile))
                            {
                                <a href="javascript:;" class="bind" hidefocus="true" flag="mobile">绑定</a>
                            }
                            else
                            {
                                @:@mobile
                            }
                            }
                        </span>
                    </li>
                    <li>邮箱：<span id="spanBindEmail" title="@email">@{
                        if (string.IsNullOrEmpty(email))
                        {
                                <a href="javascript:;" class="bind" hidefocus="true" flag="email">绑定</a>
                        }
                        else
                        {@:@SH.StringSubstrLen(email, 16)
                            }
                            }                        
                        </span>
                    </li>
                </ul>
                <div class="clear"></div>
            </div>
            <div class="user_level">
                <p class="lv"><span id="spanLevel">@curLevel</span>级</p>
                <p>距离下一级还要：<span id="spanNextLevelINum">@nextLevelNeedINum</span> i豆</p>
            </div>
            <div class="clear"></div>
        </div>
        <div class="menu_k"><span class="on" url="home"><a href="javascript:;" class="p1" hidefocus="true">我的首页</a></span><span url="task"><a href="javascript:;" class="p2" hidefocus="true">做任务</a><div id="TaskCount" class="dotter" style="display:none;"></div></span>@*<span url="privilege"><a href="javascript:;" class="p3" hidefocus="true">领特权</a></span>*@<span url="rights"><a href="javascript:;" class="p4" hidefocus="true">增值权限</a><div id="UserRightsCount" class="dotter"></div></span><span url="jp" id="jpcenter"><a href="javascript:;" class="p5" hidefocus="true">奖品中心</a></span></div>
        
        <div class="main_act"><div class="tc_loading" id="tc_loading" style="display:none">数据加载中...</div>
        <div class="mask" id="tc_mask" style="display:none"></div></div>
        <div class="clear"></div>
        <div class="bottom_bar">
            @{
                if (ViewBag.TipsInfoList != null && ViewBag.TipsInfoList.Count > 0)
                {
                   
                 <ul class="LineScroll">
                    @foreach (MC_TipsInfo tipsInfo in ViewBag.TipsInfoList)
                    {
                        if (string.IsNullOrEmpty(tipsInfo.LinkUrl))
                        {<li>@tipsInfo.Tips</li>}
                        else
                        {
                            <li><a href="@tipsInfo.LinkUrl" style="color:white;text-decoration:underline;" hidefocus="true" target="_blank">@tipsInfo.Tips</a></li>
                        }
                    }
                 </ul>
                 
                }
                }
        </div>
    </div>
    <div class="pop_k" style="display:none;">
    <div class="nr">
      <p>绑定<span id="spanTips">邮箱</span><span style="font-size:12px;">（绑定后，可用于找回密码或作为登录账号）</span></p>
      <div class="ipt_k">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            @{
                if (associatedLogin == "1") //联合登录
                {
                    <tr>
                        <td align="left" id="tdBindAccountTxt">邮箱账号</td>
                        <td colspan="2" align="right"><input type="text" class="ipt1 inputbg1" maxlength="25" id="txtBindAccount" value="" /></td>
                      </tr>
                      <tr>
                        <td width="67" align="left">&nbsp;</td>
                        <td width="94" align="left"><a href="javascript:;" class="btn1" id="btnSend" hidefocus="true">发送验证码</a></td>
                        <td align="right"><input type="text" class="ipt2" maxlength="6" id="txtAuthcode" value="" /></td>
                      </tr>
                      <tr>
                        <td align="left"><span id="spanSet">设置密码</span></td>
                        <td colspan="2" align="right"><input type="password" class="ipt1" maxlength="12" id="txtPwd" value="" /></td>
                      </tr>
                }
                else
                {
                    <tr>
                        <td align="left">登录密码</td>
                        <td colspan="2" align="right"><input type="password" class="ipt1" maxlength="12" id="txtPwd" value="" /></td>
                      </tr>
                      <tr>
                        <td align="left" id="tdBindAccountTxt">邮箱账号</td>
                        <td colspan="2" align="right"><input type="text" class="ipt1 inputbg1" maxlength="25" id="txtBindAccount" value="" /></td>
                      </tr>
                      <tr>
                        <td width="67" align="left">&nbsp;</td>
                        <td width="94" align="left"><a href="javascript:;" class="btn1" id="btnSend" hidefocus="true">发送验证码</a></td>
                        <td align="right"><input type="text" class="ipt2" maxlength="6" id="txtAuthcode" value="" /></td>
                      </tr>
                }
                }          
          <tr>
            <td colspan="2"><span id="spanMsg" style="color:red;"></span></td>
            <td align="right"><a href="javascript:;" id="btnBind" class="btn1 done" style="width:70px;" hidefocus="true">提交</a>&nbsp;<a href="javascript:;" class="btn1" id="btnClose" style="width:70px;" hidefocus="true">关闭</a></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
    <input type="hidden" id="hidetab" value="@ViewBag.tab" />
    <input type="hidden" id="hidN" value="b570fe04448f2787e6857be7c5dc6f4eccd66ff6922a7b08094716a8c7ffe0cdaadb68c8716cf151cad9c99a2cce28b9182b1b3b52ae597847012be6ae62350bb3842c3af853f4ab68e086afcf9efd28785f39038f25aaff42e60b7bf424f3a8f5b33dd996836b4985ae7c52c003d8de249ab767af1eda382212200599135cbf" />
    <input type="hidden" id="hidE" value="010001" />
    <input type="hidden" id="hidUserName" value="@userName" />
    <input type="hidden" id="hidLoginType" value="@associatedLogin" />
    <input type="hidden" id="hidContinueLoginDays" value="@continueLoginDays" />
    <input type="hidden" id="hidContinueLoginTxt" value="@continueLoginTxt" />
    <input type="hidden" id="hidTaskID" value="@completedTaskID" />
</body>

<script src="@SH.GetStaticFile("IStockClientStatic/js/EMWEBUIscrollBar.js")" type="text/javascript"></script>
<script src="@SH.GetStaticFile("IStockClientStatic/js/istockfunc.js")" type="text/javascript"></script>
<script src="@SH.GetStaticFile("IStockClientStatic/js/rasall.js")" type="text/javascript"></script>
<script src="@SH.GetStaticFile("IStockClientStatic/js/common.js")" type="text/javascript"></script>
</html>

<script type="text/javascript">
    var www = "@Url.Content("~/")", url = "", curUrl = "", bindFlag = "", countdownNum = 60, sendAccount = "",
        set_cd, loginType = $("#hidLoginType").val(),jquery_ajax;
    
    $(document).ready(function () {
        $("#scrollBoxPic").height(250);

        $(".scrollBox").jscroll({ W: "8px", IW: "8px", CurrT: 0, Bar: { Pos: "up" }, Btn: { btn: false }, Fn: function () { } }).hover(function (e) {
            var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
            if (!scrlbr.hasClass("non")) {
                scrlbr.addClass("mon").stop(true, true, false).show();
            }
        }, function (e) {
            var thisbx = $(this), scrlbr = $(this).find(".jscroll-e");
            if (!scrlbr.hasClass("non")) {
                scrlbr.removeClass("mon");
                if (scrlbr.hasClass("vxdrag")) { } else {
                    //scrlbr.fadeOut("slow");
                }
            }
        });

        

        (function ($) {
            $.fn.extend({
                scrolline: function () {
                    var _this = this
                    , $this = $(this);
                    return $this.each(function (idx, elm) {
                        var curbx = elm, $curbx = $(elm), $litm = $("li", $curbx), Timer = null;
                        function startScroll() {
                            if ($litm.length > 1) {
                                Timer = setInterval(function () {
                                    $("li:eq(0)", $curbx).stop(true, true).animate({ "margin-top": "-20px" }, 300, "", function () {
                                        $("li:eq(0)", $curbx).appendTo(curbx).css({ "margin-top": "0px" });
                                    })
                                }, 10000);
                            }
                        }
                        startScroll();
                        $curbx.hover(function () {
                            clearInterval(Timer);
                        }, function () {
                            startScroll();
                        });
                    });
                }
            });
        })(jQuery);

        $(".cover").click(function () {
            $(".pop_tx").show(1, function () {
                ReSetScroll();
            });            
        });

        $("#ulUserPic li").click(function () {
            name = $(this).attr("name");
            url = $(this).attr("url");
            _this = $(this);

            $.ajax({
                type: "post",
                url: www + "mc/cp",
                data: { p: name },
                datatype: "text",
                success: function (data) {
                    if (data == "1") {
                        $("#ulUserPic li").removeClass("on");
                        _this.addClass("on");
                        $(".user_pic img").attr("src", url);
                        
                        ISTOCK_FUNC_CHANGEUSERPIC(name);
                    }
                    else {
                        //alert(data);
                    }
                },
                beforeSend: function () {
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert(XMLHttpRequest.status);
                }
            });
        });

        $(".close").click(function () {
            $(".pop_tx").hide();
            //$(".pop_tx").delay(200).fadeOut('slow');
        });

        $(".menu_k span").click(function () {
            $(".menu_k span").removeClass("on");
            $(this).addClass("on");

            url = $(this).attr("url");

            if (url == curUrl) {
                return;
            }
            else {
                curUrl = url;
            }

            if (jquery_ajax) {
                jquery_ajax.abort();
            }

            jquery_ajax = $.ajax({
                type: "post",
                url: www + "mc/" + url,
                data: {  },
                datatype: "html",
                success: function (data) {
                    $(".main_act").html(data);
                    switch (url) {
                        case "home":
                            $.getScript("http://cbjs.baidu.com/js/m.js", function () {
                                BAIDU_CLB_fillSlotAsync("943373", "divAdT");
                                BAIDU_CLB_fillSlotAsync("943374", "divAdL");
                                BAIDU_CLB_fillSlotAsync("943375", "divAdR");
                            });
                            break;
                        case "rights":
                            $.getScript("http://cbjs.baidu.com/js/m.js", function () {
                                BAIDU_CLB_fillSlotAsync("943376", "divAd");
                            });
                            break;
                        default:
                            break;
                    }

                    $("#tc_loading").hide();
                    $("#tc_mask").hide();
                },
                beforeSend: function () {
                    $("#tc_loading").show();
                    $("#tc_mask").show();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert(XMLHttpRequest.status);
                }
            });

            //定位到奖品中心
            if ($("#hidetab").val() == "3") {
                $(".menu_k #jpcenter").trigger('click');
            }
        });

        

        $("#spanUserName").click(function () {
            $(this).hide();
            $("#txtUserName").show();
            
            setSelection(document.getElementById('txtUserName'), $("#txtUserName").val().length);
        });

        $("#txtUserName").blur(function () {
            var _this = $(this);
            var newnick = $(this).val();

            if (newnick == "" || newnick == $("#hidUserName").val()) {
                _this.hide();
                $("#spanUserName").show();
            }
            else {
                $.ajax({
                    type: "post",
                    url: www + "mc/cn",
                    data: { nick: escape(newnick) },
                    datatype: "text",
                    success: function (data) {                        
                        var arrData = data.split("^");

                        if (arrData != null && arrData != undefined && arrData.length == 2 && arrData[0] == "1") {
                            ISTOCK_FUNC_CHANGENICKNAME(newnick);

                            $("#hidUserName").val(newnick);
                            $("#txtUserName").val(newnick);
                            $("#txtUserName").hide();

                            $("#spanUserName").show();
                            $("#spanUserName").html(arrData[1]);
                        }
                        else {
                            _this.hide();
                            $("#txtUserName").val($("#hidUserName").val());

                            if (data != "") {
                                $("#spanUserNameTips").show();
                                $("#spanUserNameTips").html(data);

                                setTimeout(function () { $("#spanUserNameTips").hide(); $("#spanUserName").show(); }, 1000);
                            }
                            else {                                
                                $("#spanUserName").show();                                
                            }
                        }
                    },
                    beforeSend: function () {
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //alert(XMLHttpRequest.status);
                    }
                });
            }
        });

        $(".bind").click(function () {
            bindFlag = $(this).attr("flag");
            $("#spanMsg").html("");
            $("#txtBindAccount").val("");
            $("#txtAuthcode").val("");
            $("#txtPwd").val("");

            if (loginType == "1") {
                $("#txtPwd").addClass("inputbg5");
            }
            else {
                $("#txtPwd").addClass("inputbg6");
            }

            clearTimeout(set_cd);
            $("#btnSend").removeClass("done");
            $("#btnSend").html("发送验证码");
            
            switch (bindFlag) {
                case "mobile":
                    $("#tdBindAccountTxt").html("手机号码");
                    $("#txtBindAccount").removeClass("inputbg1").addClass("inputbg2");
                    
                    $("#spanTips").html("手机");
                    $("#txtAuthcode").removeClass("inputbg3").addClass("inputbg4");
                    
                    $(".pop_k").css("left", "120px");
                    $(".pop_k").show();
                    //$(".pop_k").delay(200).fadeIn('slow');
                    break;
                case "email":
                    $("#tdBindAccountTxt").html("邮箱账号");
                    $("#txtBindAccount").removeClass("inputbg2").addClass("inputbg1");
                    
                    $("#spanTips").html("邮箱");
                    $("#txtAuthcode").removeClass("inputbg4").addClass("inputbg3");

                    $(".pop_k").css("left", "246px");
                    $(".pop_k").show();
                    //$(".pop_k").delay(200).fadeIn('slow');
                    break;
                default:
                    break;
            }

            if (loginType == "1") {
                $("#spanSet").html("&nbsp;");
                $("#txtPwd").hide();
            }
            else {
                $("#txtPwd").focus();
            }
        });

        $("#txtPwd").keyup(function (e) {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg5");
                $(this).removeClass("inputbg6");
            }
            else {
                if (loginType == "1") {
                    $("#txtPwd").addClass("inputbg5");
                }
                else {
                    $("#txtPwd").addClass("inputbg6");
                }
            }
        });

        $("#txtPwd").blur(function () {
            if ($("#txtPwd").val() == "") {
                if (loginType == "1") {
                    $("#txtPwd").addClass("inputbg5");
                }
                else {
                    $("#txtPwd").addClass("inputbg6");
                }
            }
        });

        $("#txtBindAccount").keyup(function (e) {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg1");
                $(this).removeClass("inputbg2");
            }
            else {
                switch (bindFlag) {
                    case "mobile":
                        $(this).addClass("inputbg2");
                        break;
                    case "email":
                        $(this).addClass("inputbg1");
                        break;
                    default:
                        break;
                }
            }
        });

        $("#txtBindAccount").blur(function () {
            if ($(this).val() == "") {
                switch (bindFlag) {
                    case "mobile":
                        $(this).addClass("inputbg2");
                        break;
                    case "email":
                        $(this).addClass("inputbg1");
                        break;
                    default:
                        break;
                }
            }
        });

        $("#txtAuthcode").keyup(function (e) {
            if ($(this).val() != "") {
                $(this).removeClass("inputbg3");
                $(this).removeClass("inputbg4");
            }
            else {
                switch (bindFlag) {
                    case "mobile":
                        $(this).addClass("inputbg4");
                        break;
                    case "email":
                        $(this).addClass("inputbg3");
                        break;
                    default:
                        break;
                }
            }
        });

        $("#txtAuthcode").blur(function () {
            if ($(this).val() == "") {
                switch (bindFlag) {
                    case "mobile":
                        $(this).addClass("inputbg4");
                        break;
                    case "email":
                        $(this).addClass("inputbg3");
                        break;
                    default:
                        break;
                }
            }
        });

        $("#btnClose").click(function () {
            $(".pop_k").hide();
            //$(".pop_k").delay(200).fadeOut('slow');
        });

        $("#btnSend").click(function () {
            if ($(this).hasClass("done")) {
                return;
            }

            var account = $("#txtBindAccount").val();

            if (account == "") {
                switch (bindFlag) {
                    case "email":
                        $("#spanMsg").html("输入常用邮箱账号");
                        break;
                    case "mobile":
                        $("#spanMsg").html("请输入常用手机号码");
                        break;
                    default:
                        break;
                }

                $("#txtBindAccount").focus();
            }
            else {
                switch (bindFlag) {
                    case "email":
                        if (!account.match(/^\w+((-\w+)|(\.\w+))*\@@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
                            $("#spanMsg").html("邮箱格式错误");
                            $("#txtBindAccount").focus();
                            return;
                        }
                        else {
                            $("#spanMsg").html("");
                        }
                        break;
                    case "mobile":
                        if (!account.match(/^1[3|4|5|8][0-9]\d{4,8}$/)) {
                            $("#spanMsg").html("手机号码格式错误");
                            $("#txtBindAccount").focus();
                            return;
                        }
                        else {
                            $("#spanMsg").html("");
                        }
                        break;
                    default:
                        break;
                }

                var rsaAccount = rsaFunc(account);

                if (rsaAccount == "") {
                    $("#spanMsg").html("加密传输失败");
                }
                else {
                    $.ajax({
                        type: "post",
                        url: www + "mc/send",
                        data: { flag: bindFlag, account: rsaAccount },
                        datatype: "text",
                        success: function (data) {
                            switch (data) {
                                case "1":
                                case "2":
                                case "21":
                                    sendAccount = account;
                                    $("#spanMsg").html("发送成功");
                                    $("#txtAuthcode").focus();

                                    $("#btnBind").removeClass("done");

                                    countdownNum = 60;
                                    countdown();

                                    if (data == "2")    //存在登录密码
                                    {
                                        $("#spanSet").html("登录密码");
                                        $("#txtPwd").show();
                                    }
                                    else {
                                        if (data == "1" && loginType == "1") { //绑定的账号不存在 且 当前为联合登录，需要设置登录密码
                                            $("#spanSet").html("设置密码");
                                            $("#txtPwd").show();
                                        }
                                    }
                                    break;
                                default:
                                    if (data != "" && data != "0") {
                                        $("#spanMsg").html(data);
                                    }
                                    else {
                                        $("#spanMsg").html("发送失败");
                                    }
                                    $("#btnSend").removeClass("done");
                                    $("#btnSend").html("发送验证码");
                                    break;
                            }
                        },
                        beforeSend: function () {
                            $("#btnSend").addClass("done");
                            $("#btnSend").html("发送中...");
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            //alert(XMLHttpRequest.status);
                        }
                    });
                }
            }
        });

        $("#btnBind").click(function () {
            if (!$(this).hasClass("done")) {
                var pwd = $("#txtPwd").val();
                var account = $("#txtBindAccount").val();
                var code = $("#txtAuthcode").val();
                
                if (pwd == "" && $("#txtPwd").css("display") != "none")
                {
                    $("#spanMsg").html("请输入爱炒股登录密码");
                    $("#txtPwd").focus();
                    return;
                }
                else if (account != sendAccount)
                {
                    switch (bindFlag) {
                        case "mobile":
                            $("#spanMsg").html("手机号码输入错误");
                            break;
                        case "email":
                            $("#spanMsg").html("邮箱输入错误");
                            break;
                        default:
                            break;
                    }
                    $("#txtBindAccount").focus();

                    return;
                }
                else if (code == "" || code.length != 6) {
                    $("#spanMsg").html("请输入6位验证码");
                    $("#txtAuthcode").focus();

                    return;
                }
                else {
                    var rsaAccount = rsaFunc(account);

                    var rsaPwd = "";
                    if (pwd != "") {
                        rsaPwd = rsaFunc(pwd);
                    }

                    $.ajax({
                        type: "post",
                        url: www + "mc/bind",
                        data: { flag: bindFlag, account: rsaAccount, pwd: rsaPwd, code: code,logintype:loginType },
                        datatype: "text",
                        success: function (data) {
                            switch (data) {
                                case "":
                                    $("#spanMsg").html("绑定失败");
                                    break;
                                case "1":                                    
                                    $("#spanMsg").html("绑定成功");
                                    $("#btnClose").click();

                                    switch (bindFlag) {
                                        case "mobile":
                                            $("#spanBindMobile").html(mobileFormat(account));
                                            break;
                                        case "email":
                                            $("#spanBindEmail").html(emailFormat(account,13));
                                            $("#spanBindEmail").attr("title", account);
                                            break;
                                        default:
                                            break;
                                    }

                                    if ($(".bind").length == 0) {
                                        ISTOCK_FUNC_COMPLETETASK(1, 30, "验证手机、邮箱");

                                        if (url == "task") {
                                            curUrl = "";
                                            $(".menu_k span")[1].click();
                                        }
                                    }
                                    break;
                                default:
                                    if (data.length > 10) {
                                        $("#spanMsg").html("<span title='" + data + "'>" + data.substring(0,10) + "...</span>");
                                    }
                                    else {
                                        $("#spanMsg").html(data);
                                    }
                                    break;
                            }
                        },
                        beforeSend: function () {
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            //alert(XMLHttpRequest.status);
                        }
                    });
                }
            }
        });

        $(".LineScroll").scrolline();

        getUserRights();    //获取增值权限

        if ($("#hidContinueLoginTxt").val() != "")
        {
            ISTOCK_FUNC_COMPLETETASK("18", $("#hidContinueLoginTxt").val(), "连续登录奖励");

            $.ajax({
                type: "post",
                url: www + "mc/cl",
                data: { },
                datatype: "text",
                success: function (data) {
                },
                beforeSend: function () {
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    //alert(XMLHttpRequest.status);
                }
            });
        }

        $(".menu_k span")[0].click();
    });

    function setSelection(editor, pos) {
        if (editor.setSelectionRange) {
            editor.focus();
            editor.setSelectionRange(pos, pos);
        } else if (editor.createTextRange) {
            var textRange = editor.createTextRange();
            textRange.collapse(true);
            textRange.moveEnd("character", pos);
            textRange.moveStart("character", pos);
            textRange.select();
        }
    }

    function formatLongTxt(txt, length)
    {
        if (txt == undefined || txt == "") {
            return "";
        }
        else {
            if (txt.length > length) {
                return txt.substring(0, length) + "...";
            }
            else {
                return txt;
            }
        }
    }

    function rsaFunc(text) {
        var rsa = new RSAKey();

        rsa.setPublic($("#hidN").val(), $("#hidE").val());
        var res = rsa.encrypt(text);

        if (res) {
            return linebrk(hex2b64(res), 64);
        }
        else {
            return "";
        }
    }

    function countdown() {//btnSend
        $("#btnSend").html("倒计时 " + countdownNum);        

        if (countdownNum > 0) {
            countdownNum = countdownNum - 1;

            set_cd = setTimeout(countdown, 1000);
        }
        else {
            $("#btnSend").removeClass("done");
            $("#btnSend").html("发送验证码");
        }
    }

    function mobileFormat(mobile)
    {
        if (mobile == "" || mobile.length != 11) {
            return "";
        }
        else {
            return mobile.substring(0, 3) + "****" + mobile.substring(7, 11);
        }
    }

    function emailFormat(email,len)
    {
        if (email == "" || email.length <= len) {
            return email;
        }
        else {
            return email.substring(0, len) + "...";
        }
    }

    function ISTOCK_FUNC_ONLINETIME()
    {
        $.ajax({
            type: "post",
            url: www + "mc/ot",
            data: {  },
            datatype: "text",
            success: function (data) {
                if (data != "") {
                    var obj = eval('(' + data + ')');

                    if (obj != null) {
                        ISTOCK_FUNC_COMPLETETASK(obj.tid, obj.inum, obj.name);

                        if (url == "task") {
                            curUrl = "";
                            $(".menu_k span")[1].click();
                        }
                    }
                }
            },
            beforeSend: function () {
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //alert(XMLHttpRequest.status);
            }
        });
    }

    function ISTOCK_FUNC_NOTICETASK(tid)
    {
        if (tid != "") {
            var isComplete = "0";
            var taskids = $("#hidTaskID").val();

            if (taskids != undefined && taskids != "")
            {
                var arrTaskID = taskids.split(",");

                for (var i = 0; i < arrTaskID.length; i++)
                {
                    if (arrTaskID[i] != "")
                    {
                        if (arrTaskID[i] == tid)
                        {
                            isComplete = "1";
                            break;
                        }
                    }
                }
            }
            
            if (isComplete == "0") {
                $.ajax({
                    type: "post",
                    url: www + "mc/ct",
                    data: { tid: tid },
                    datatype: "text",
                    success: function (data) {
                        if (data != "") {
                            var obj = eval('(' + data + ')');

                            if (obj != null && obj.TaskInfo != null) {
                                $("#spanINum").html(obj.iNum);
                                $("#spanLevel").html(obj.Level);
                                $("#spanNextLevelINum").html(obj.NextLeveliNum - obj.iNum);

                                ISTOCK_FUNC_COMPLETETASK(tid, obj.TaskInfo.iNum, obj.TaskInfo.Name);

                                if (url == "task") {
                                    curUrl = "";
                                    $(".menu_k span")[1].click();
                                }
                            }
                        }
                    },
                    beforeSend: function () {
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //alert(XMLHttpRequest.status);
                    }
                });
            }
        }
    }

    function getUserRights()
    {
        var count = 0;
        var data = ISTOCK_FUNC_GETUSERRIGHTS();

        if (data != "") {
            var obj = eval(data);

            if (obj != null && obj.length > 0)
            {
                var now = new Date();
                $.each(obj, function (i) {
                    if (compareDate(now, new Date(obj[i].enddate))) {
                        count++;
                    }
                });
            }
        }

        if (count > 0) {
            $("#UserRightsCount").html(count);
        }
        else {
            $("#UserRightsCount").hide();
        }
    }
</script>